
<template>
  <a-modal
          :width="1370"
          :visible="visible"
          :confirmLoading="confirmLoading"
          @cancel="handleCancel"
  >
    <iframe :src="reportUrl" frameborder="0" style="width:100%;height:750px;" id="iframeBox" @load="onIframeLoad"></iframe>
    <template slot="footer">
      <a-button @click="handleCancel">关闭</a-button>
    </template>
  </a-modal>
</template>

<script>
    import pick from 'lodash.pick'
    import { getAction,postAction } from '@/api/manage'
    import Vue from 'vue'
    export default {
        name: 'PrintView',
        components: {},
        data () {
            return {
                visible: false,
                confirmLoading: false,
                formInfo: {},
                reportUrl:'',
                edt:false,
                options: {
                    toolbar: true,
                    url: 'data-source',
                },
                url: {
                    print: '/system/eyeStudentTestRecord/printinfo',
                    savept:'/system/eyeStudentTestRecord/savept'
                }
            }
        },
        created () {
            let self = this
            window.close = (close)=>{
                self.close()
            }
        },
        methods: {
            show (record) {
                getAction(this.url.print, {
                    id: record.id
                }, 0).then(res => {
                    this.$emit('ok', 'obj')
                    this.formInfo = res.result.data
                    localStorage.setItem('eyeStudentRecord', JSON.stringify(res.result.data))
                    localStorage.setItem('eyeStudent', JSON.stringify(res.result.student))
                    localStorage.setItem('remap', JSON.stringify(res.result.remap))
                    this.reportUrl = "../printReport.html?recordid="+record.id
                }).finally(() => {
                })
                this.visible = true

            },
            onIframeLoad() {
                // 在这里可以执行一些初始化操作，比如设置全局函数
                window.parent.callFromIframe = this.prints;
            },
            prints(){
                postAction(this.url.savept, this.formInfo).then(res => {
                    this.$message.success(res.content)
                    this.close()
                }).finally(() => {
                    this.confirmLoading = false
                })
            },
            // 确定
            handleSubmit () {
                this.visible = false
            },
            // 关闭
            handleCancel () {
                this.close()
            },
            close () {
                this.$emit('close')
                this.visible = false
            }
        }
    }
</script>


